package org.example.listener;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.example.model.message.AccountChangeMessage;
import org.example.service.AccountInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * topic需要和生产者的topic一致，consumerGroup属性是必须指定的，内容可以随意
 * @author shenguangyang
 */
@Component
@RocketMQMessageListener(
        nameServer = "${rocketmq.name-server}",
        topic = "topic_txmsg",
        consumerGroup = "consumer_txmsg_group_bank2")
public class TxmsgListener implements RocketMQListener<AccountChangeMessage> {
    private static final Logger log = LoggerFactory.getLogger(TxmsgListener.class);
    @Resource
    private AccountInfoService accountInfoService;

    @Override
    public void onMessage(AccountChangeMessage message) {
        accountInfoService.addBalance(message);
    }
}
